-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/add distribution module examples #208
Conversation
… `distribution` module
WalkthroughThe recent update brings significant enhancements to the Changes
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #208 +/- ##
==========================================
- Coverage 29.71% 29.01% -0.71%
==========================================
Files 17 17
Lines 2564 2630 +66
==========================================
+ Hits 762 763 +1
- Misses 1766 1831 +65
Partials 36 36 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 19
Configuration used: .coderabbit.yaml
Files selected for processing (15)
- .coderabbit.yaml (1 hunks)
- client/chain/chain.go (5 hunks)
- client/chain/chain_test_support.go (2 hunks)
- examples/chain/distribution/1_SetWithdrawAddress/example.go (1 hunks)
- examples/chain/distribution/3_WithdrawValidatorCommission/example.go (1 hunks)
- examples/chain/distribution/4_FundCommunityPool/example.go (1 hunks)
- examples/chain/distribution/query/1_ValidatorDistributionInfo/example.go (1 hunks)
- examples/chain/distribution/query/2_ValidatorOutstandingRewards/example.go (1 hunks)
- examples/chain/distribution/query/3_ValidatorCommission/example.go (1 hunks)
- examples/chain/distribution/query/4_ValidatorSlashes/example.go (1 hunks)
- examples/chain/distribution/query/5_DelegationRewards/example.go (1 hunks)
- examples/chain/distribution/query/6_DelegationTotalRewards/example.go (1 hunks)
- examples/chain/distribution/query/7_DelegatorValidators/example.go (1 hunks)
- examples/chain/distribution/query/8_DelegatorWithdrawAddress/example.go (1 hunks)
- examples/chain/distribution/query/9_CommunityPool/example.go (1 hunks)
Additional comments: 5
.coderabbit.yaml (1)
- 1-8: The automation configuration in
.coderabbit.yaml
looks good and aligns with standard development workflows. It's a great addition for streamlining the review and chat reply process based on the specified base branches.client/chain/chain.go (4)
- 171-180: The addition of methods related to the distribution module in the
ChainClient
interface is correctly implemented. These methods cover a wide range of functionalities necessary for interacting with the distribution aspects of a blockchain network, such as fetching validator distribution info, outstanding rewards, commissions, slashes, delegation rewards, total rewards, delegator validators, delegator withdraw address, and community pool details. This expansion aligns with the PR objectives and enhances the library's capabilities significantly.- 217-217: The inclusion of the
distributionQueryClient
field in thechainClient
struct is a necessary addition to facilitate interactions with the distribution module. This change is well-implemented and follows the pattern established by other module-specific query clients in the struct. It ensures that the new distribution-related methods have the required client to make gRPC calls to the blockchain network.- 312-312: Initializing the
distributionQueryClient
within theNewChainClient
function is correctly done. This step is crucial for setting up the client with the ability to interact with the distribution module right from the creation of achainClient
instance. The use ofdistributiontypes.NewQueryClient(conn)
is consistent with how other module-specific clients are initialized, ensuring uniformity and maintainability.- 1513-1576: The implementation of the distribution module-related methods in the
chainClient
struct is thorough and covers all the functionalities outlined in the PR objectives. Each method correctly constructs the request object, makes the gRPC call using thedistributionQueryClient
, and returns the response. This comprehensive implementation enables users of the library to interact with various aspects of the distribution module, enhancing the library's utility for blockchain network interactions. It's also worth noting that the methods are implemented consistently with existing patterns in the codebase, which aids in maintainability.
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"os" | ||
|
||
"github.com/InjectiveLabs/sdk-go/client" | ||
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | ||
"github.com/InjectiveLabs/sdk-go/client/common" | ||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider organizing imports by grouping standard library imports separately from third-party imports for better readability.
import (
"encoding/json"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
"github.com/cosmos/cosmos-sdk/x/distribution/types" | |
"os" | |
"github.com/InjectiveLabs/sdk-go/client" | |
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | |
"github.com/InjectiveLabs/sdk-go/client/common" | |
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"github.com/cosmos/cosmos-sdk/x/distribution/types" | |
"github.com/InjectiveLabs/sdk-go/client" | |
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | |
"github.com/InjectiveLabs/sdk-go/client/common" | |
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | |
) |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding sensitive information such as the mnemonic and keyring passphrase ("12345678"
) in the source code is a security risk. Consider using environment variables or secure vaults for sensitive data.
response, err := chainClient.AsyncBroadcastMsg(msg) | ||
|
||
if err != nil { | ||
panic(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling for AsyncBroadcastMsg
is done by panicking. While this might be acceptable for an example script, in production code, it's better to handle errors gracefully. Consider logging the error or returning it to the caller.
"fmt" | ||
"github.com/cosmos/cosmos-sdk/types/query" | ||
"os" | ||
|
||
"github.com/InjectiveLabs/sdk-go/client" | ||
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | ||
"github.com/InjectiveLabs/sdk-go/client/common" | ||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous file, consider organizing imports by grouping standard library imports separately from third-party imports for better readability.
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/InjectiveLabs/sdk-go/client"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
"fmt" | |
"github.com/cosmos/cosmos-sdk/types/query" | |
"os" | |
"github.com/InjectiveLabs/sdk-go/client" | |
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | |
"github.com/InjectiveLabs/sdk-go/client/common" | |
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"os" | |
"github.com/cosmos/cosmos-sdk/types/query" | |
"github.com/InjectiveLabs/sdk-go/client" | |
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | |
"github.com/InjectiveLabs/sdk-go/client/common" | |
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | |
) |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same security concern applies here regarding the hardcoding of sensitive information. Use environment variables or secure vaults instead.
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(res, "", " ") | ||
fmt.Print(string(str)) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script for querying validator commission follows the established pattern of initialization and querying. The handling of sensitive information, such as the private key, needs to be securely managed to adhere to security best practices.
- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} |
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(res, "", " ") | ||
fmt.Print(string(str)) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example script for querying validator distribution info is consistent with the patterns observed in previous files. The recommendation regarding the secure handling of sensitive information, such as the private key, remains critically important.
- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} |
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(res, "", " ") | ||
fmt.Print(string(str)) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script for querying validator outstanding rewards follows the established pattern of initialization and querying. The handling of sensitive information, such as the private key, needs to be securely managed to adhere to security best practices.
- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" | |
ctx := context.Background() | |
res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} |
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | ||
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5" | ||
ctx := context.Background() | ||
|
||
res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(res, "", " ") | ||
fmt.Print(string(str)) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example script for querying delegation rewards is consistent with the patterns observed in previous files. The recommendation regarding the secure handling of sensitive information, such as the private key, remains critically important.
- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | |
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5" | |
ctx := context.Background() | |
res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} | |
func main() { | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | |
validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5" | |
ctx := context.Background() | |
res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress) | |
if err != nil { | |
fmt.Println(err) | |
} | |
str, _ := json.MarshalIndent(res, "", " ") | |
fmt.Print(string(str)) | |
} |
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5" | ||
|
||
msg := &types.MsgWithdrawValidatorCommission{ | ||
ValidatorAddress: validatorAddress, | ||
} | ||
|
||
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | ||
response, err := chainClient.AsyncBroadcastMsg(msg) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(response, "", " ") | ||
fmt.Print(string(str)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script for withdrawing validator commission is well-structured and demonstrates the transaction broadcast process effectively. As with previous scripts, ensure that sensitive information, such as the private key, is securely managed and not hardcoded.
- "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
+ os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5" | |
msg := &types.MsgWithdrawValidatorCommission{ | |
ValidatorAddress: validatorAddress, | |
} | |
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | |
response, err := chainClient.AsyncBroadcastMsg(msg) | |
if err != nil { | |
panic(err) | |
} | |
str, _ := json.MarshalIndent(response, "", " ") | |
fmt.Print(string(str)) | |
} | |
network := common.LoadNetwork("testnet", "lb") | |
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | |
if err != nil { | |
panic(err) | |
} | |
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | |
os.Getenv("HOME")+"/.injectived", | |
"injectived", | |
"file", | |
"inj-user", | |
"12345678", | |
os.Getenv("PRIVATE_KEY"), // keyring will be used if pk not provided | |
false, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx, err := chainclient.NewClientContext( | |
network.ChainId, | |
senderAddress.String(), | |
cosmosKeyring, | |
) | |
if err != nil { | |
panic(err) | |
} | |
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | |
chainClient, err := chainclient.NewChainClient( | |
clientCtx, | |
network, | |
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | |
) | |
if err != nil { | |
panic(err) | |
} | |
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5" | |
msg := &types.MsgWithdrawValidatorCommission{ | |
ValidatorAddress: validatorAddress, | |
} | |
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | |
response, err := chainClient.AsyncBroadcastMsg(msg) | |
if err != nil { | |
panic(err) | |
} | |
str, _ := json.MarshalIndent(response, "", " ") | |
fmt.Print(string(str)) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yaml
Files selected for processing (6)
- client/chain/chain.go (5 hunks)
- client/chain/chain_test_support.go (2 hunks)
- examples/chain/distribution/1_SetWithdrawAddress/example.go (1 hunks)
- examples/chain/distribution/3_WithdrawValidatorCommission/example.go (1 hunks)
- examples/chain/distribution/4_FundCommunityPool/example.go (1 hunks)
- examples/chain/distribution/query/4_ValidatorSlashes/example.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
- client/chain/chain.go
- client/chain/chain_test_support.go
- examples/chain/distribution/1_SetWithdrawAddress/example.go
- examples/chain/distribution/3_WithdrawValidatorCommission/example.go
- examples/chain/distribution/4_FundCommunityPool/example.go
- examples/chain/distribution/query/4_ValidatorSlashes/example.go
distribution
module.Summary by CodeRabbit
ChainClient
interface to include distribution module methods for blockchain interactions.